import axios from 'axios'

const state = () => ({
  menu: [],
  hotPlace: []
})

const mutations = {
  setMenu(state, val) {
    state.menu = val
  },
  setHotPlace(state, val) {
    state.hotPlace = val
  }
}

const actions = {
  setMenu: ({commit}, menu) => {
    commit('setMenu', menu)
  },
  setHotPlace: async ({commit}, city) => {
    const {status: hotPlaceStatus, data: {result}} = await axios.get('/search/hotPlace', {
      params: {
        city: city.replace('市', '')
      }
    })
    commit('setHotPlace', hotPlaceStatus === 200 ? result : [])
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
